#include <bits/stdc++.h>
#incldue < stdio.h>

using namespace std;
struct node
{ /*总分,c语言成绩,python成绩,数学成绩,线性代数成绩,英语成绩,形势与政策成绩,概率与统计成绩,离散数学成绩*/
    string name;
    int sum, cScore, pythonScore, mathScore, linearScore, englishScore, situationAndPolicyScore, probabilityAndStatisticsScore, discreteMathematicsScore;
    node *pre, *next;
};
extern "C"
{
    void begin(char *s);
    void sort();
    void swap(node *a, node *b);

    void createaList();
    void show();

} //继承自c
char path[1024];
struct label
{
    string label1, label2, label3, label4, label5, label6, label7, label8, label9, label10;
};
int n = 0;
label *first;
void swap(node *a, node *b);
void sort();
void createaList();
void begin(char *s);
void show();
node *root;
void write();
int main()
{
    char s[] = "3.xls";
    begin(s);

    return 0;
}
void begin(char *s)
{

    strcpy(path, s);
    createaList();
    sort();
    show();
    write();
}
void swap(node *a, node *b)
{
    if (a == b)
        return;

    if (a->next != b)
    {
        node *pre = a->pre, *next = a->next;
        a->pre = b->pre;
        a->pre->next = a;
        a->next = b->next;
        if (a->next != NULL)
            a->next->pre = a;
        b->next = next;
        b->next->pre = b;
        b->pre = pre;
        if (b->next != NULL)
            b->pre->next = b;
    }
    else
    {
        node *pre = a->pre, *next = b->next;
        if (b->next != NULL)
            b->next->pre = a;
        a->pre->next = b;
        a->pre = b;
        b->next = a;
        b->pre = pre;
        a->next = next;
    }
}

void sort()
{
    for (node *i = root->next; i != NULL; i = i->next)
        for (node *j = i->next; j != NULL; j = j->next)
        {
            if (i->sum < j->sum)
            {
                swap(i, j);
                node *temp = i;
                i = j;
                j = temp;
            }
        }
}
void show()
{
    node *temp = root->next;
    while (temp->next != NULL)
    {
        printf("%d ", temp->sum);
        temp = temp->next;
    }
}
void createaList()
{
    root = new node;
    root->next = root->pre = NULL;
    ifstream file;
    file.open(path);

    node *temp = root;
    char alpha;
    first = new label;
    file >> first->label1 >> first->label2 >> first->label3 >> first->label4 >> first->label5 >> first->label6 >> first->label7 >> first->label8 >> first->label9 >> first->label10;
    while (1)
    {
        if (file.eof())
        {
            n--;
            break;
        }
        temp->next = new node;
        temp->next->pre = temp;
        temp->next->next = NULL;
        temp = temp->next;
        file >> temp->name >> temp->cScore >> temp->pythonScore >> temp->mathScore >> temp->discreteMathematicsScore >> temp->linearScore >> temp->englishScore >> temp->probabilityAndStatisticsScore >> temp->probabilityAndStatisticsScore >> temp->sum;
        n++;
    }
}
void write()
{
    ofstream file;
    file.open(path);

    node *temp = root;
    file << first->label1 << "\t" << first->label2 << "\t" << first->label3 << "\t" << first->label4 << "\t" << first->label5 << "\t" << first->label6 << "\t" << first->label7 << "\t" << first->label8 << "\t" << first->label9 << "\t" << first->label10 << endl;
    for (int i = 0; i < n; i++)
    {

        temp = temp->next;
        file << temp->name << "\t" << temp->cScore << "\t" << temp->pythonScore << "\t" << temp->mathScore << "\t" << temp->discreteMathematicsScore << "\t" << temp->linearScore << "\t" << temp->englishScore << "\t" << temp->probabilityAndStatisticsScore << "\t" << temp->probabilityAndStatisticsScore << "\t" << temp->sum << endl;
    }
}